<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" th:href="@{res/css/amazeui.min.css}">
    <link rel="stylesheet" th:href="@{res/css/admin.css}">
<!--    <script src="js/jquery-3.4.1.min.js"></script>-->
    <script type="text/javascript" th:src="@{/js/jquery-1.11.3.min.js}"></script>
    <script th:src="@{/myplugs/js/plugs.js}"></script>

    <style>
        .admin-main{
            padding-top: 0px;
        }
    </style>
</head>
<body>
<div class="am-cf admin-main">
    <!-- content start -->
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-g">
                <div class="am-form am-form-horizontal"
                      style="padding-top:30px;">
                    <div class="am-form-group">
                        <label for="menuName" class="am-u-sm-3 am-form-label">
                            菜单名称 </label>
                        <div class="am-u-sm-9">
                            <input type="text" id="menuName"
                                   name="menuName">
                        </div>
                    </div>
                    <div class="am-form-group">
                        <label for="belongTo" class="am-u-sm-3 am-form-label">
                            隶&nbsp;&nbsp;属&nbsp;&nbsp;方</label>
                        <div class="am-u-sm-9">
                            <select id="belongTo">
                                <option value="1">品牌商</option>
                                <option value="2">借卖方</option>
                                <option value="3">管理员</option>
                            </select>
                        </div>
                    </div>
                    <div class="am-form-group">
                        <div class="am-u-sm-9 am-u-sm-push-3">
                            <input type="button" class="am-btn am-btn-primary" value="确认" id="confirm"/>
                            <input type="button" class="am-btn am-btn-primary" value="取消" id="cancel"/>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    function GetRequest() {
        var url = location.search; //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for(var i = 0; i < strs.length; i ++) {
                theRequest[strs[i].split("=")[0]]=decodeURIComponent(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }

    $(function(){
        var Request = new Object();
        Request = GetRequest();
        var name = Request["name"];
        var menu_id  = Request["menu_id"];
        var id = Request["id"];
        var level = Request["level"];
        console.log(name);
        console.log(menu_id);
        console.log(id);
        console.log(level);
        $("#menuName").val(name);
        if(menu_id == 1){
        $("#belongTo").get(0).selectedIndex = 0;
        }else if(menu_id == 6){
            $("#belongTo").get(0).selectedIndex = 1;
        }else{
            $("#belongTo").get(0).selectedIndex = 2;
        }

        $("#confirm").click(function(){
            var name = $("#menuName").val();
            var belongTo = $("#belongTo").val();
            var menu_id;
            if (belongTo == 1)
                menu_id = 1;
            else if(belongTo == 2)
                menu_id = 6;
            else
                menu_id = 12;

            $.ajax({
                type:"post",
                url:"/menu/updateMenu",
                data:{name:name,menu_id:menu_id,id:id,level:level},
                dataType:"text",
                success:function(result){
                    console.log(result);
                    parent.location.reload();
                },
                error:function(result){
                    console.log(result);
                }
            })
        })

        //取消
        $("#cancel").click(function(){
            window.parent.location.reload();
        })
    })
</script>
</html>